package org.biz.modules.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.biz.common.Result;
import org.biz.exception.BussinessLogicException;
import org.biz.modules.entity.VerifyCodeParam;
import org.biz.modules.service.ShortMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author: sukai
 * Date: 2021/3/27
 */
@RestController
@RequestMapping("/api/shortMsg")
@Api(tags = "短信相关接口相关接口")
public class ShortMsgController {

	private final Logger logger = LoggerFactory.getLogger(ShortMsgController.class);

	@Autowired
	private ShortMsgService shortMsgService;


	@RequestMapping(value = "/findback/", method = RequestMethod.POST)
	@ApiOperation(notes = "", value = "找回密码验证码")
	public Result<SendSmsResponse> sendFindbackCode(String phone) throws BussinessLogicException {
		return Result.OK(shortMsgService.sendMessage(phone, "findback", null));
	}

	@RequestMapping(value = "/register", method = RequestMethod.POST)
	@ApiOperation(notes = "", value = "获取登录验证码")
	public Result<SendSmsResponse> sendRegisterCode(String phone) throws BussinessLogicException {
		return Result.OK(shortMsgService.sendMessage(phone, "register", null));
	}

	@ApiOperation(notes = "", value = "验证短信接口")
	@ApiImplicitParam(name = "param", value = "手机号phone,验证码code,动作action,\n" +
			"action目前支持register注册和findback找回密码", required = true, dataType = "VerifyCodeParam")
	@RequestMapping(value = "/verifyCode/", method = RequestMethod.POST)
	public  Result<String> verifyCode(@RequestBody VerifyCodeParam param) throws BussinessLogicException {

		return Result.OK(shortMsgService.verify(param.getPhone(), param.getAction(), param.getCode()));
	}
}
